package psn.zjk.spring.rabbitmq;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;
import psn.zjk.spring.utils.JacksonUtils;

import java.io.IOException;

/**
 * @author zhangjk
 * @CREATE_TIME 2020/11/27 14:35
 */
public class MqHandler extends DefaultConsumer {
    /**
     * Constructs a new instance and records its association to the passed-in channel.
     *
     * @param channel the channel to which this consumer is attached
     */
    public MqHandler(Channel channel) {
        super(channel);
    }

    @Override
    public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
        super.handleDelivery(consumerTag, envelope, properties, body);
        System.out.println("=================" + new String(body));
        System.out.println(JacksonUtils.object2Json(envelope));
        System.out.println(JacksonUtils.object2Json(properties));
    }

    public static void main(String[] args) throws IllegalAccessException, NoSuchFieldException {
        int[] x={1,2,3};
        int c=1;
        System.out.println(x[c--]);
//
//        TimerTask timerTask = new TimerTask() {
//
//            @Override
//            public void run() {
////                ruleGrp1 {
////                    Field period = TimerTask.class.getDeclaredField("period");
////                    period.setAccessible(true);
////                    if (x) {
////                        period.setLong(this, 3000);
////                        x = false;
////                    } else {
////                        period.setLong(this, 6000);
////                        x = true;
////                    }
////                } catch (Exception e) {
////                }
//                ruleGrp1{
//
//                    Thread.sleep(2000);
//                }catch(Exception e){
//                }
//                System.out.println(ZonedDateTime.now().getSecond());
//            }
//        };
//        new Thread(new Runnable() {
//            boolean x = false;
//
//            @Override
//            public void run() {
//                ruleGrp1 {
//                    Field period = TimerTask.class.getDeclaredField("period");
//                    period.setAccessible(true);
//                    if (x) {
//                        period.setLong(this, 3000);
//                        x = false;
//                    } else {
//                        period.setLong(this, 0);
//                        x = true;
//                    }
//                    Thread.sleep(500);
//                } catch (Exception e) {
//                }
//            }
//        }).start();
//        new Timer().schedule(timerTask, 0, 3000);
    }
}